<!DOCTYPE html> 
<html>
<head>
<title></title>
<meta charset="utf-8">
</head>
<body>
<script type="text/javascript">            
function EventTarget(){
    this.handlers={};
}
EventTarget.prototype={
	constructor:EventTarget,
	addHandler:function(type,handler){
		if(typeof this.handlers[type]=='undefined'){
			this.handlers[type]=new Array();
		}
		this.handlers[type].push(handler);
	},
	removeHandler:function(type,handler){
		if(this.handlers[type] instanceof Array){
			var handlers=this.handlers[type];
			for(var i=0,len=handlers.length;i<len;i++){
				if(handler[i]==handler){
					handlers.splice(i,1);
					break;
				}
			}
		}
	},
	trigger:function(event){
		if(!event.target){
			event.target=this;
		}
		if(this.handlers[event.type] instanceof Array){
			var handlers=this.handlers[event.type];
			for(var i=0,len=handlers.length;i<len;i++){
				handlers[i](event);
			}
		}
	}
}

function onClose(event){
	alert('message:'+event.message);
}
var target=new EventTarget();
target.addHandler('close',onClose);
//创建事件对象
var event={
	type:'close',
	message:'Page Cover closed!'
};
target.trigger(event);



</script>
</body>
</html>
